package com.common.base.task;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public interface ITask<T> extends Callable<T> {
    /**
     * Indicates the current status of the task. Each status will be set only
     * once during the lifetime of a task.
     */
    interface Status {
        /**
         * Indicates that the task has not been executed yet.
         */
        int PENDING = 1;
        /**
         * Indicates that the task is running.
         */
        int RUNNING = 2;
        /**
         * Indicates that the task has finished.
         */
        int FINISHED = 3;
    }

    /**
     * Return the current status of the task.
     *
     * @return
     */
    int getStatus();

    void setStatus(int status);

    /**
     * Cancel the current task.
     */
    void cancel();

    /**
     * Returns true if this task has been canceled.
     */
    boolean isCanceled();

    /**
     * Set the priority of thread.
     *
     * @param priority
     */
    void setThreadPriority(int priority);

    default long getTimeout() {
        return 5000;
    }

    default String getName() {
        return null;
    }

    void setFutureTask(FutureTask task);
}
